.data
	
	a: .long 7
	
	b: .long 77
	
	outform: .string "%d ist ggt von %d und %d.\n"



.text

.globl main

main:
	
	movl a, %eax 		 # a into reg %eax
	
	movl b, %ebx 		 # b into reg %bx
	
	pushl %eax      	 # Push %eax into stack
	
	pushl %ebx	 	 # Push %ebx into stack
	
	

	call ggt		 # Call Subprogram ggt
	
	pushl b			 # b for String
	
	pushl a			 # a for String
	
	pushl %eax		 # Result for String
	
	pushl $outform		 # All Variables into String
	
	call printf		 # Print All in String
	

	addl $8, %esp		 # Fill Stackpointer

	

	movl $1, %eax 		 # Exit
	
	int $0x80		 # Software Interrupt



.globl ggt

ggt:
	
	pushl %ebp		 # 
	
	movl %esp, %ebp

	
	
	movl 4(%ebp),%eax	 # a in basepointer
	
	movl 8(%ebp),%ebx	 # b in basepointer



.L1:	
	
	cmpl $0, %ebx	  	 # while b = 0
	
	je .L3			 # go to leave
	

	cmpl %ebx, %eax	         # if statement
	
	jg .L2			 # go to L2(if true)

		
	subl %eax, %ebx		 # else b = b - a 
	
	jmp .L1			 # go to L1



.L2:		
	
	subl %ebx, %eax		 # a = a - b
	
	jmp .L1			 # go to L1



.L3:
	
	popl %ebp		 # Leave Subprogram
	
	movl %eax, 8(%ebp)
	
	ret
